<template>
  <div>
    <div>个人中心</div>
    <footerPage />
  </div>
</template>

<script>
import footerPage from '../../components/footer_page'
import axios from 'axios'
import Qs from 'qs'
import wx from 'weixin-js-sdk'

export default {
  name: 'Myself',
  components: {
    footerPage,
  },
  data() {
    return {}
  },
  computed: {},
  created() {
    this.getConfig()
  },
  mounted() {},
  methods: {
    getConfig() {
      const param = {
        url: window.location.href,
      }
      axios.post('/weChat/getPayConfig', param).then(function(response) {
        if (response.data.code == 200) {
          var data = response.data.data
          wx.config({
            debug: ture, // 这里一般在测试阶段先用ture，等打包给后台的时候就改回false,
            appId: data.appid,
            timestamp: data.timestamp,
            nonceStr: data.noncestr,
            signature: data.signature,
            jsApiList: ['chooseWXPay'],
          })
          wx.ready(function() {
            wx.checkJsApi({
              jsApiList: ['chooseWXPay'],
              success: function(res) {
                console.log('seccess')
                console.log(res)
              },
              fail: function(res) {
                console.log('fail')
                console.log(res)
              },
            })
          })
        }
      }).catch(function(error) {

      })
    },
    createdPayInfo(id) {
      const param = {
        payAmount: 0.01,
      }
      axios.post('/createdPayInfo', Qs.stringify(param)).then(function(response) {
        if (response.data.code == 200) {
          wx.ready(function() {
            wx.chooseWXPay({
              appId: data.appId,
              timestamp: data.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
              nonceStr: data.nonceStr, // 支付签名随机串，不长于 32
              package: data.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
              signType: data.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
              paySign: data.paySign, // 支付签名
              success: function(res) {

              },
              cancel: function(res) { // 提示引用的是mint-UI里toast

              },
              fail: function(res) {

              },
            })
          })
        }
      }).catch(function(error) {

      })
    },
  },
}
</script>

<style scoped lang="scss">

</style>
